package com.mht.book.operation.impl;

import com.mht.book.entity.book.Book;
import com.mht.book.entity.book.BookList;
import com.mht.book.operation.Operations;

import java.util.Objects;
import java.util.Scanner;

/**
 * @author wangfusheng
 * @version 1.0.0
 * @ClassName EditOperation.java
 * @Description 修改图书信息
 * @createTime 2022/12/316:37
 */
public class EditOperation implements Operations {

    @Override
    public void work(BookList bookList) {
        boolean isEdit = false;
        System.out.println("修改图书信息！");
        System.out.println("请输入您要修改的图书名称：");
        Scanner sc = new Scanner(System.in);
        String inputName = sc.nextLine();
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            Book book = bookList.getBooks()[i];
            //查询到了需要修改的图书
            if(Objects.equals(inputName,book.getName())){
                System.out.println("您要修改的图书，已经找到，信息如下：");
                System.out.println(book);
                System.out.println();
                System.out.println("请选择你要修改的图书信息：");
                System.out.println("1、修改名称 2、修改作者 3、修改类型 4、修改价格");
                int key = sc.nextInt();
                switch (key){
                    case 1:
                        System.out.println("请输入要修改的图书名称：");
                        String newName = sc.next();
                        book.setName(newName);
                        System.out.println("图书名称已经修改成功！新书名为：《"+newName+"》");
                        isEdit = true;
                        System.out.println();
                        break;
                    case 2:
                        System.out.println("请输入图书要修改的作者名称：");
                        String newAuthor = sc.next();
                        book.setAuthor(newAuthor);
                        System.out.println("图书的作者已修改为："+newAuthor);
                        isEdit = true;
                        System.out.println();
                        break;
                    case 3:
                        System.out.println("请输入修改的图书的类型：");
                        String newType = sc.next();
                        book.setType(newType);
                        System.out.println("图书的类型已修改为："+newType);
                        isEdit = true;
                        System.out.println();
                        break;
                    case 4:
                        System.out.println("请输入修改的图书的价格：");
                        int newPrice = sc.nextInt();
                        book.setPrice(newPrice);
                        System.out.println("图书的价格已修改为："+newPrice);
                        isEdit = true;
                        System.out.println();
                        break;
                }
            }
//            else {
//                System.out.println("--------抱歉，没有查询到您要修改的图书");
//            }
        }
        if(isEdit == false){
            System.out.println("抱歉，没有查询到您要修改的图书！");
            System.out.println();
        }
    }
//    public static void main(String[] args) {
//        EditOperation edit = new EditOperation();
//        edit.work(new BookList());
//    }
}
